package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateRoleGetPageDTO;
import com.itlong.cloud.POJO.PO.OperateRolePO;
import com.itlong.cloud.operate.service.IOperateRoleService;
import com.itlong.cloud.user.operate.IOperateRoleServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <desc>
 *      运营-资源菜单业务处理暴露接口实现类
 * </desc>
 *
 * @createDate 2017/09/21
 */
@RestController
public class OperateRoleServiceResource implements IOperateRoleServiceClient{
    @Autowired
    IOperateRoleService iOperateRoleService;

    /**
     * <desc>
     *      获取分页列表
     * </desc>
     *
     * @param operateRoleGetPageDTO 分页查询参数DTO
     * @return 分页模型
     * @author Jiaqi.X
     * @createDate 2017/09/25
     */
    @Override
    @RequestMapping(path = "/operate/system/role/getPage")
    public Page<OperateRolePO> getPage(@RequestBody OperateRoleGetPageDTO operateRoleGetPageDTO) throws Exception {
        return iOperateRoleService.getPage(operateRoleGetPageDTO);
    }

    /**
     * <desc>
     *      添加角色
     * </desc>
     * @param operateRolePO 角色实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/25
     */
    @Override
    @RequestMapping(path = "/operate/system/role/save")
    public Integer save(@RequestBody OperateRolePO operateRolePO) throws Exception {
        return iOperateRoleService.save(operateRolePO);
    }

    /**
     * <desc>
     *      修改角色
     * </desc>
     * @param operateRolePO 角色实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/25
     */
    @Override
    @RequestMapping(path = "/operate/system/role/update")
    public Integer update(@RequestBody OperateRolePO operateRolePO) throws Exception {
        return iOperateRoleService.update(operateRolePO);
    }

    /**
     * <desc>
     *      查询单条角色
     * </desc>
     *
     * @param operateRolePO 角色实体
     * @return 角色实体
     * @author Jiaqi.X
     * @createDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/system/role/getOne")
    public OperateRolePO getOne(@RequestBody OperateRolePO operateRolePO) {
        return iOperateRoleService.getOne(operateRolePO);
    }

    /**
     * <desc>
     *      删除角色
     * </desc>
     *
     * @param roleIds 角色id数组
     * @return 执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/25
     */
    @Override
    @RequestMapping(path = "/operate/system/role/delete")
    public Integer delete(@RequestParam("roleIds") String roleIds) throws Exception {
        return iOperateRoleService.delete(roleIds);
    }

    /**
     * <desc>
     *      保存角色菜单
     * </desc>
     *
     * @param roleId 角色id
     * @param functionIds 资源id 多个,号分隔
     * @return
     * @author Jiaqi.X
     * @createTime 2017/09/26
     */
    @Override
    @RequestMapping(path = "/operate/system/role/saveRoleFunction")
    public Integer saveRoleFunction(@RequestParam("roleId") String roleId,
                                    @RequestParam(value = "functionIds",required = false) String functionIds,
                                    @RequestParam(value = "assessFunctionIds",required = false) String assessFunctionIds,
                                    @RequestParam("myUserName") String myUserName) throws Exception{
        return iOperateRoleService.saveRoleFunction(roleId,functionIds,assessFunctionIds,myUserName);
    }

    /**
     * <desc>
     *      获取所有角色
     * </desc>
     *
     * @return
     * @author Jiaqi.X
     * @createDate 2017/10/09
     */
    @Override
    @RequestMapping(path = "/operate/system/role/getList")
    public List<OperateRolePO> getList(@RequestParam("userId") String userId) {
        return iOperateRoleService.getList(userId);
    }

    /**
     * <desc>
     *      为用户分配角色
     * </desc>
     * @param roleId    角色id
     * @param allotUsers    需要分配的人员id 多个，号分隔
     * @param userIds 当前列表所有人员id 多个，号分隔
     * @return
     */
    @Override
    @RequestMapping(path = "/operate/system/role/saveRoleUsers")
    public Integer saveRoleUsers(
                @RequestParam("roleId") String roleId,
                @RequestParam("allotUsers") String allotUsers,
                @RequestParam("userIds") String userIds) throws Exception {
        return iOperateRoleService.saveRoleUsers(roleId,allotUsers,userIds);
    }

    /**
     * <desc>
     *      判断角色名是否已存在
     * </desc>
     *
     * @param roleName 角色名称
     * @return
     * @author Jiaqi.X
     * @createDate 2017/12/25
     */
    @RequestMapping(path = "/operate/system/role/checkRoleNameExist")
    public Integer checkRoleNameExist(@RequestParam("roleName") String roleName){
        return iOperateRoleService.checkRoleNameExist(roleName);
    }
}
